Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load proposals sequentially #1506

Merged
merged 26 commits into from
Apr 5, 2024
Merged

Load proposals sequentially #1506

merged 26 commits into from
Apr 5, 2024

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Mar 30, 2024

Closes #1509
Closes #1457
Closes #1464

User facing changes

  • Loads Azorius proposals sequentially instead of all at once.
  • No change to how Multisig or Snapshot proposals / transactions are loaded.

Behind the scenes changes

  • Moved a handful of event listeners from various places (mostly useAzoriusProposals, but also useERC20LinearStrategy and useERC721LinearStrategy) into their own new top-level hook, useAzoriusListeners
  • Optimized proposal object creation logic to no longer need to fetch Voted events or ProposalExecuted events for each proposal. Instead, fetch them all just once before processing each proposal. Because they're not indexed, we have to just get all of them anyway. So just pass them down into the proposal processing and filter the same static set per proposal.
  • Plenty of other stuff, but I guess mostly just a lot of refactoring.
    • Start with useAzoriusProposals, then check out azorius.ts, then check out useAzoriusListeners, then check out the other little things strewn around.

Potential follow up work

  • More consistent and accurate "loading" components for the proposals. Both when they start (still seeing "no proposals" message before the first one loads in), and while they're loading (would be good to have a "more proposals loading" component at the bottom that stays there until they're all done).
  • Cache completed proposals in local storage, so we don't need to re-fetch them.

Testing

  • Bring up a DAO with many Azorius proposals: see how they load.
  • Before they're finished loading in, switch to a new DAO (in-app, via Favorites or Hierarchy or Search): see how the first DAO's proposals don't populate into this new DAO yay.
  • All other user experience and behavior should be unchanged.

Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for fractal-dev ready!

Name Link
🔨 Latest commit db8823b
🔍 Latest deploy log https://app.netlify.com/sites/fractal-dev/deploys/660dca99bb9993000869e3bb
😎 Deploy Preview https://deploy-preview-1506.app.dev.fractalframework.xyz
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@adamgall adamgall force-pushed the load-proposals-synchronously branch from d374c2f to ab359c0 Compare March 30, 2024 20:45
@adamgall adamgall force-pushed the load-proposals-synchronously branch from 2a2794a to bec53f2 Compare March 31, 2024 00:15
@adamgall adamgall changed the title WIP: Load proposals synchronously WIP: Load proposals sequentially Apr 1, 2024
@adamgall adamgall marked this pull request as ready for review April 3, 2024 20:48
@adamgall adamgall requested review from mudrila and tomstuart123 April 3, 2024 20:48
@adamgall adamgall requested a review from Da-Colon April 3, 2024 20:48
@adamgall adamgall changed the title WIP: Load proposals sequentially Load proposals sequentially Apr 3, 2024
@@ -92,7 +92,6 @@
"@testing-library/react": "^14.2.1",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/remove-markdown": "^0.3.4",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that this unused package was hanging around, so removed it.

@@ -89,7 +89,7 @@ export default function Markdown({ truncate, content, collapsedLines = 6 }: IMar
maxWidth="100%"
>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
remarkPlugins={truncate ? [] : [remarkGfm]}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't try to render URLs as actual links if we're showing markdown in "truncate" mode.

We're using "truncate" when showing markdown in Proposal List cards, which are giant anchor tags, so we don't want to try to render more anchor tags within those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't have anything to do with the rest of this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file, removed a bunch of references to governance type from the dependency arrays of useEffects, which weren't used in the actual hooks.

@mudrila @Da-Colon do you know why these were here? Are they necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this bandaid, safe to remove. This was to try to make it wait a little longer before it tries to setup the listener. which is no longer needed as this work fixes the root problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely some leftovers, seems like those references are not needed here

Comment on lines -113 to -130
useEffect(() => {
if (!azoriusContractAddress || !baseContracts || !type) {
return;
}
const azoriusContract =
baseContracts.fractalAzoriusMasterCopyContract.asProvider.attach(azoriusContractAddress);
const timeLockPeriodFilter = azoriusContract.filters.TimelockPeriodUpdated();
const timelockPeriodListener: TypedListener<TimelockPeriodUpdatedEvent> = timelockPeriod => {
action.dispatch({
type: FractalGovernanceAction.UPDATE_TIMELOCK_PERIOD,
payload: BigNumber.from(timelockPeriod),
});
};
azoriusContract.on(timeLockPeriodFilter, timelockPeriodListener);
return () => {
azoriusContract.off(timeLockPeriodFilter, timelockPeriodListener);
};
}, [azoriusContractAddress, action, baseContracts, type]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this event listener to new useAzoriusListeners

Comment on lines -120 to -138
useEffect(() => {
if (!azoriusContractAddress || !baseContracts || !type) {
return;
}
const azoriusContract =
baseContracts.fractalAzoriusMasterCopyContract.asProvider.attach(azoriusContractAddress);

const timeLockPeriodFilter = azoriusContract.filters.TimelockPeriodUpdated();
const timelockPeriodListener: TypedListener<TimelockPeriodUpdatedEvent> = timelockPeriod => {
action.dispatch({
type: FractalGovernanceAction.UPDATE_TIMELOCK_PERIOD,
payload: BigNumber.from(timelockPeriod),
});
};
azoriusContract.on(timeLockPeriodFilter, timelockPeriodListener);
return () => {
azoriusContract.off(timeLockPeriodFilter, timelockPeriodListener);
};
}, [azoriusContractAddress, action, baseContracts, type]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied line-for-line in useERC20LinearStrategy.ts, so removed here. I removed it from the other file too, and it's now in useAzoriusListeners.

@@ -48,6 +49,7 @@ export default function useDAOController() {
useFractalTreasury();
useERC20Claim();
useSnapshotProposals();
useAzoriusListeners();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create the listeners.

Comment on lines +64 to +67
| {
type: FractalGovernanceAction.SET_AZORIUS_PROPOSAL;
payload: FractalProposal;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new action for setting one single Azorius proposal into state

Comment on lines +33 to +35
{
batch: true,
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't hurt right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not at all. I think we will see these benefits when we conform more to the Wagmi patterns and hooks ie useContractsRead

Comment on lines -138 to -139
const proposalExecutedFilter = azoriusContract.filters.ProposalExecuted();
const proposalExecutedEvents = await azoriusContract.queryFilter(proposalExecutedFilter);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to re-fetch these events for each proposal, can just do it once way up above and pass the full array down here for filtering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of refactoring in here to deal with teasing out the slight differences between ERC20 strategy contract and ERC721 strategy contract.

@tomstuart123
Copy link

This works really well for me. Load time of 1 (rather than multiple) proposal(s) feels quicker and they all come in in the right order (from new to late)

I raised at standup my desire for more comms on load time but @adamgall highlighted he raised these above. This led me to create the card here - #1517

Copy link
Contributor

@mudrila mudrila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Copy link
Contributor

@Da-Colon Da-Colon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, gonna approved. just some questions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this bandaid, safe to remove. This was to try to make it wait a little longer before it tries to setup the listener. which is no longer needed as this work fixes the root problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this bandaid, safe to remove. This was to try to make it wait a little longer before it tries to setup the listener. which is no longer needed as this work fixes the root problem

() => safeAPI.getSafeInfo(utils.getAddress(_daoAddress)),
5,
);
safeInfo = await safeAPI.getSafeInfo(utils.getAddress(_daoAddress));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been here for a long time. This was to safe guard against network hiccups. But yeah generally probably safe to remove

Comment on lines +33 to +35
{
batch: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not at all. I think we will see these benefits when we conform more to the Wagmi patterns and hooks ie useContractsRead

src/utils/azorius.ts Show resolved Hide resolved
Comment on lines +298 to +306
export const decodeTransactions = async (
_decode: (value: string, to: string, data?: string | undefined) => Promise<DecodedTransaction[]>,
_transactions: MetaTransaction[],
) => {
const decodedTransactions = await Promise.all(
_transactions.map(async tx => _decode(tx.value.toString(), tx.to, tx.data)),
);
return decodedTransactions.flat();
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this appear from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It came from here: https://github.com/decentdao/fractal-interface/pull/1506/files/db8823bfe3abb068126f25dac7174601deedfaf2#diff-051684bdee1b274984af1420c9548bf363cd143b226a8d3f2692daddf0148afbL40-L50

I just moved it into azorius.ts because there was another new file (useAzoriusListeners.ts) that needed it.

@adamgall adamgall merged commit 20b4ba3 into develop Apr 5, 2024
7 checks passed
@adamgall adamgall deleted the load-proposals-synchronously branch April 5, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants